Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@solid-primitives/rootless
Advanced tools
A collection of helpers that aim to simplify using reactive primitives outside of reactive roots, asynchronously after the root initialization, or just working with roots in general.
createSubRoot
- Creates a reactive sub root, that will be automatically disposed when it's owner does.createCallback
- A wrapper for creating callbacks with runWithOwner
.runWithRoot
- Use reactive primitives outside of reactive roots.runWithSubRoot
- Like runWithRoot
, but creates a sub root instead.npm install @solid-primitives/rootless
# or
yarn add @solid-primitives/rootless
createSubRoot
Creates a reactive sub root, that will be automatically disposed when it's owner does.
Use it for creating roots nested in other roots.
import { createSubRoot } from "@solid-primitives/rootless";
createRoot(dispose => {
createSubRoot(disposeSubRoot => {
createEffect(...)
// disposes only the sub root
disposeSubRoot()
})
// disposes the outer root, AND all the nested sub roots
dispose()
})
function createSubRoot<T>(fn: (dispose: () => void) => T, owner?: Owner | null): T;
createCallback
A wrapper for creating callbacks with runWithOwner
.
It gives you the option to use reactive primitives after root setup and outside of effects.
Why?
All of the callback-based (in opposite to effect-based) events is Solid don't have a root, because the root is changed synchronously after initialization finishes. So normally that would prevent you from using reactive primitives there.
runWithOwner
attatches whatever computations created inside, to the owner passed to it.
// in component body
const handleClick = createCallback(() => {
// the effect will be created normally, attached to the component's reactive root
createEffect(() => {...})
})
// in jsx
<button onClick={handleClick} />
const createCallback = <T extends AnyFunction>(
callback: T,
owner?: Owner | null
): T
runWithRoot
Helper for simplifying usage of Solid's reactive primitives outside of components (reactive roots).
// when fn doesn't return anything
const dispose = runWithRoot(() =>
createEffect(() => {
console.log(count());
})
);
// when fn returns something
const [double, dispose] = runWithRoot(() => createMemo(() => count() * 2));
type runWithRootReturn<T> = T extends void | undefined | null
? Dispose
: [returns: T, dispose: Dispose];
const runWithRoot = <T>(fn: () => T, detachedOwner?: Owner): runWithRootReturn<T>
runWithSubRoot
Helper for simplifying usage of Solid's reactive primitives outside of components (reactive roots). A sub root will be automatically disposed when it's owner does.
// when fn doesn't return anything
const dispose = runWithSubRoot(() =>
createEffect(() => {
console.log(count());
})
);
// when fn returns something
const [double, dispose] = runWithSubRoot(() => createMemo(() => count() * 2));
type runWithRootReturn<T> = T extends void | undefined | null
? Dispose
: [returns: T, dispose: Dispose];
const runWithSubRoot = <T>(fn: () => T, detachedOwner?: Owner): runWithRootReturn<T>
0.0.100
Initial release as a Stage-1 primitive.
FAQs
A collection of helpers that aim to simplify using reactive primitives outside of reactive roots, and managing disposal of reactive roots.
The npm package @solid-primitives/rootless receives a total of 18,497 weekly downloads. As such, @solid-primitives/rootless popularity was classified as popular.
We found that @solid-primitives/rootless demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.